Ext.define('Ext.app.SurplusCoursePortlet', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.gridportlet',
    height: 180,

    initComponent: function(){
        var store = Ext.create('Ext.data.Store', {
            fields: [
               {name: 'id'},
               {name: 'student__company__cn_name'},
               {name: 'student__student_manager__name'},
               {name: 'student__name'},
               {name: 'course__name'},
               {name: 'study_type'},
               {name: 'course_times'},
               {name: 'use_course_times'}
            ],
		    proxy: {
		        type: 'ajax',
		        url: '/usercontrol/index_course_warning/',
		        actionMethods:'post',
		        reader: {
		            type: 'json',
		            root: 'rows',
		            totalProperty: 'totalCount'
		        }
		    },
		    autoLoad: true
        });

        Ext.apply(this, {
            height: this.height,
            store: store,
            stripeRows: true,
            columnLines: true,
            columns: [
            {
            	text   : '校区',
                sortable : false,
                width: 80,
                dataIndex: 'student__company__cn_name'
            },
            {
            	text   : '学管师',
                sortable : false,
                width: 55,
                dataIndex: 'student__student_manager__name'
            },
            {
                text   : '学生',
                sortable : false,
                width: 55,
                dataIndex: 'student__name'
            },{
                text   : '课程',
                width: 100,
                sortable : false,
                dataIndex: 'course__name'
            },{
                text   : '已消耗课时',
                sortable : false,
                width: 65,
                dataIndex: 'use_course_times'
            },{
                text   : '剩余课时',
                sortable : false,
                width: 55,
                dataIndex: 'course_times',
                flex:1,
                renderer:function(value, metaData, record){
                	return parseInt(value)-parseInt(record.get('use_course_times'));
                }
            }]
        });

        this.callParent(arguments);
	    Ext.TaskManager.start({
		    run: function(){
		        store.load();
		    },
		    interval:3600000  // 1小时
	    });         
    }
});

